package com.easonji.core.log;

import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

/**
 * @ClassName: LogManager
 * @Description: 日志管理器
 * @Author: LiuJun
 * @date: 2018/07/08 18:28
 * @Version: 1.0
 * @Copyright: Copyright (c) 2018 - 2019
 */
public class LogManager {

    /**
     * 异步操作记录日志的线程池
     */
    private ExecutorService executor = new ThreadPoolExecutor(5, 10, 0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingDeque<Runnable>(1024), new ThreadFactoryBuilder().setNameFormat("log-pool-%d").build(),
            new ThreadPoolExecutor.AbortPolicy());

    private LogManager() {
    }

    public static LogManager logManager = new LogManager();

    public static LogManager me() {
        return logManager;
    }

    public void executeLog(TimerTask task) {
        executor.execute(task);
    }
}
